﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using DotNetOpenAuth.ApplicationBlock;
using System.Web.Security;
using Google.GData.Client;
using Google.Contacts;

namespace SSOExample
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (base.Request.QueryString["Act"] == "SignOut")
            {
                FormsAuthentication.SignOut();
                base.Session.Clear();
                base.Response.Redirect(FormsAuthentication.DefaultUrl);
            }

            if (string.IsNullOrEmpty(base.Page.User.Identity.Name))
            {
                this.plcMember.Visible = false;
                this.plcAnonymous.Visible = true;
            }
            else
            {
                this.ltrUsername.Text = base.Page.User.Identity.Name;
                this.plcMember.Visible = true;
                this.plcAnonymous.Visible = false;

                if (this.ltrUsername.Text.Contains("https://www.google.com/accounts"))
                {
                    RequestSettings settings = new RequestSettings("yourApp");
                    settings.AutoPaging = false;

                    ContactsRequest request = new ContactsRequest(settings);
                    List<Contact> allContacts = new List<Contact>();
                    foreach (Contact localContact in request.GetContacts().Entries)
                    {
                        allContacts.Add(localContact);
                    }
                }
            }
        }
    }
}
